package top.codestudy.servicetrain;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

public class MusicService extends Service {
    private static final String TAG = "MusicService";

    public MusicService() {
        Log.i(TAG, "MusicService: ");
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Log.i(TAG, "onCreate: ");
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.i(TAG, "onStartCommand: ");
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public IBinder onBind(Intent intent) {
        Log.i(TAG, "onBind: name ==> " + intent.getStringExtra("name"));
       return new MyBinder();
    }

    @Override
    public void onRebind(Intent intent) {
        Log.i(TAG, "onRebind: name ==> " + intent.getStringExtra("name"));
        super.onRebind(intent);
    }

    @Override
    public boolean onUnbind(Intent intent) {
        Log.i(TAG, "onUnbind: ");
        return true;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.i(TAG, "onDestroy: ");
    }

    public class MyBinder extends Binder{

        public String name = "cc";

        public String getServiceName(){
            Log.i(TAG, "getServiceName: MusicService" + MusicService.this);
            return "" + MusicService.this;
        }

        public void stopService(){
            MusicService.this.stopSelf();
            Log.i(TAG, "stopService: ");
        }
    }

}
